<?php
/**
 * hognyi @taoding 2018.11.19
 *
 *
 */
namespace App\Logic;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Resources\Agent as AgentResource;
use App\Models\Area;
use PhpParser\Node\Stmt\TryCatch;

class SettingsLogic
{
	
	/**
	 * 表单数据
	 * @var array
	 */
	private $_post_data = array();
	
		
	public function __construct()
	{
		
	}

    //获取计费详情
    static public function getCompanyDetail($id){
        //$company_info = Agent::with('linkman')->where($where)->first();
        try{
            $company_info = DB::table('sys_charged_rules')
                ->where('enterprise_id', '=', $id)
                ->first();
        }catch (\Exception $e){
            echo $e->getMessage();
        }

        return $company_info;
    }
    //创建计费
    public function create($request){
	    try{
	 $create=DB::table('sys_charged_rules')
            ->insert([
                'rule_type'=>$request['rule_type'],
                'charged_standard'=>$request['charged_standard'],
                'default_back_id'=>$request['default_back_id'],
                'default_back_account'=>$request['default_back_account'],
                'enterprise_id'=>$request['enterprise_id'],
                'create_by'=>\Auth::user()->name,
                'create_date'=>$request['create_date'],
                'update_by'=>$request['update_by'],
                'update_date'=>$request['update_date'],
                'remark'=>$request['remark'],
            ]);
        }catch (\Exception $e){
	        echo $e->getMessage();
        }
        if (!$create){
            throw new \Exception('计费保存失败');
        }
    }
    //更改计费
    public function update($request,$id){
	    try{
            $isok=DB::table('sys_charged_rules')
                ->where('enterprise_id',$id)
                ->update([
                    'rule_type'=>$request['rule_type'],
                    'charged_standard'=>$request['charged_standard'],
                    'default_back_id'=>$request['default_back_id'],
                    'default_back_account'=>$request['default_back_account'],
                    'create_by'=>\Auth::user()->name,
                    'create_date'=>$request['create_date'],
                    'update_by'=>$request['update_by'],
                    'update_date'=>$request['update_date'],
                    'remark'=>$request['remark'],
                ]);
        }catch (\Exception $e){
            echo $e->getMessage();
        }
        if (!$isok){
            throw new \Exception('计费保存失败');
        }
    }
}